/*
 * @Description: 字典相关接口
 * @Author: Rfan
 * @Date: 2022-05-28 16:22:33
 * @LastEditTime: 2022-06-20 18:17:17
 */

import { IPageQuery } from '@/interfaces/global';
import { configRequest } from '@/utils/request';

// 查询字典类型列表
export interface IDicListParams {
  archiveTypeId: number;
  code?: string;
  deleted?: number;
  id?: number;
  name?: string;
  remark?: string;
}

export function fetchDicList(data: IDicListParams) {
  return configRequest({
    url: `/data-dict-type/list`,
    method: 'post',
    data
  });
}

// 分页查询字典类型列表
export interface IDicListByPageParams extends IPageQuery<IDicListParams> {}

export function fetchDicListByPage(data: IDicListByPageParams) {
  return configRequest({
    url: `/data-dict-type/page`,
    method: 'post',
    data
  });
}

// 新增字典类型
export interface IAddDicTypeParams {
  code: string;
  deleted?: number;
  id?: number;
  name: string;
  remark?: string;
}

export function addDicType(data: IAddDicTypeParams) {
  return configRequest({
    url: `/data-dict-type/`,
    method: 'post',
    data
  });
}

// 编辑字典类型
export function editDicType(data: IAddDicTypeParams) {
  return configRequest({
    url: `/data-dict-type/`,
    method: 'put',
    data
  });
}

// 删除字典类型
export function deleteDicType(id: string) {
  return configRequest({
    url: `/data-dict-type/${id}`,
    method: 'delete'
  });
}

// 查询字典项目列表
export interface IDicItemListParams {
  code?: string;
  deleted?: number;
  id?: number;
  isValid?: number;
  name?: string;
  remark?: string;
  typeId?: number;
  value?: string;
}

export function fetchDicItemList(data: IDicItemListParams) {
  return configRequest({
    url: `/data-dict/list`,
    method: 'post',
    data
  });
}

// 分页查询字典项目列表
export interface IDicItemListByPageParams extends IPageQuery<IDicItemListParams> {}

export function fetchDicItemListByPage(data: IDicItemListByPageParams) {
  return configRequest({
    url: `/data-dict/page`,
    method: 'post',
    data
  });
}

// 根据ID查询字典项目列表
export function fetchDicItemListById(dictTypeId: number) {
  return configRequest({
    url: `data-dict/by-type-id/${dictTypeId}`,
    method: 'get'
  });
}

// 新增字典项目
export interface IAddDicItemParams {
  code: string;
  deleted?: number;
  id?: number;
  isValid?: number;
  name: string;
  remark?: string;
  typeId?: number;
  value?: string;
}

export function addDicItem(data: IAddDicItemParams) {
  return configRequest({
    url: `/data-dict/`,
    method: 'post',
    data
  });
}

// 编辑字典项目
export function editDicItem(data: IAddDicItemParams) {
  return configRequest({
    url: `/data-dict/`,
    method: 'put',
    data
  });
}

// 删除字典项目
export function deleteDicItem(id: string) {
  return configRequest({
    url: `data-dict/${id}`,
    method: 'delete'
  });
}
